* This do-file makes "Table 3. First-stage technology adoption decision, 1985-2000"
* File written by Kazuma Takakura kazuma.arukakat@gmail.com (University of Tokyo)
* Last updated on April 27, 2024

set more off
use "$path_data/fninvest_experience.dta", clear

// (1)
reg fn8500 houseland land_all land_inherit success85 risk00_1std hyper00 highdisc00 high_edu high_edu2 cc85std village riceland riceland2 risk00_missing, robust
matrix result_85_1 = r(table)
scalar Rsquared_85_1 = e(r2_a)


// (2)
reg fn8500 houseland land_all land_inherit success85 risk00_1std hyper00 highdisc00 high_edu high_edu2 cc85std village age_old numhh riceland riceland2 age_missing numhh_missing risk00_missing, robust
matrix result_85_2 = r(table)
scalar Rsquared_85_2 = e(r2_a)


// (3)
reg fn8500 houseland land_all land_inherit success85 risk00_1std hyper00 highdisc00 high_edu high_edu2 cc85std village age_old age_old2 numhh numhh2 riceland riceland2 age_missing numhh_missing risk00_missing, robust
matrix result_85_3 = r(table)
scalar Rsquared_85_3 = e(r2_a)


// (4)
reg fn8500 houseland land_all land_inherit success85 risk00_1std hyper00 highdisc00 high_edu high_edu2 cc85std village riceland riceland2 age20s age30s age40s age50s age60s age70s age80s age_missing numhh13 numhh46 numhh79 numhh1013 numhh_missing risk00_missing, robust
matrix result_85_4 = r(table)
scalar Rsquared_85_4 = e(r2_a)


forvalues n = 1/4 {
forvalues item = 4/4 {
		forvalues scale = 1/28 {
		if result_85_`n'[`item', `scale']<=0.01 {
			local star85_`n'_`scale' %3s "***"
		}
		else if (result_85_`n'[`item', `scale']>0.01) & (result_85_`n'[`item', `scale']<=0.05) {
			local star85_`n'_`scale' %2s "**"
		}
		else if (result_85_`n'[`item', `scale']>0.05) & (result_85_`n'[`item', `scale']<=0.10) {
			local star85_`n'_`scale' %1s "*"
		}
		else {
			local star85_`n'_`scale'  ""
		}
	} // forvalues `scale' loop

}  // forvalues `item' loop


} // forvalues `n' loop



tempname hh2
file open `hh2' using "$path_tex/Table_first.tex", write replace
file write `hh2' "" _newline
file write `hh2' "% Author: Kazuma Takakura" _newline
file write `hh2' "% Date: `c(current_date)'" _newline
file write `hh2' "% Time: `c(current_time)'" _newline
file write `hh2' "" _newline


file write `hh2' "\begin{table}[h!]\footnotesize" _newline
file write `hh2' "  \centering" _newline
file write `hh2' "  \caption{First-stage technology adoption decision, 1985-2000}" _newline
file write `hh2' "\label{tab:firstphase}" _newline
file write `hh2' "\scalebox{0.9}{" _newline
file write `hh2' "\begin{threeparttable}" _newline

file write `hh2' "\begin{tabular}{lcccc}\toprule" _newline
file write `hh2' "  &(1)&(2)&(3)&(4) \\\midrule\midrule" _newline
file write `hh2' "  Displacement (dummy) & " %04.3f (result_85_1[1,1]) `star85_1_1'  "& " %04.3f (result_85_2[1,1]) `star85_2_1' "& " %04.3f (result_85_3[1,1]) `star85_3_1' "& " %04.3f (result_85_4[1,1]) `star85_4_1' " \\" _newline
file write `hh2' "    & (" %04.3f (result_85_1[2,1]) ") & (" %04.3f (result_85_2[2,1]) ") & (" %04.3f (result_85_3[2,1]) ") & (" %04.3f (result_85_4[2,1]) ") \\" _newline
file write `hh2' "  Land loss (dummy) & " %04.3f (result_85_1[1,2]) `star85_1_2' "& " %04.3f (result_85_2[1,2]) `star85_2_2' "& " %04.3f (result_85_3[1,2]) `star85_3_2' "& " %04.3f (result_85_4[1,2]) `star85_4_2' " \\" _newline
file write `hh2' "    & (" %04.3f (result_85_1[2,2]) ") & (" %04.3f (result_85_2[2,2]) ") & (" %04.3f (result_85_3[2,2]) ") & (" %04.3f (result_85_4[2,2]) ") \\" _newline
file write `hh2' "  Land owner (dummy) & " %04.3f (result_85_1[1,3]) `star85_1_3'  "& " %04.3f (result_85_2[1,3]) `star85_2_3' "& " %04.3f (result_85_3[1,3]) `star85_3_3' "& " %04.3f (result_85_4[1,3]) `star85_4_3' " \\" _newline
file write `hh2' "    & (" %04.3f (result_85_1[2,3]) ") & (" %04.3f (result_85_2[2,3]) ") & (" %04.3f (result_85_3[2,3]) ") & (" %04.3f (result_85_4[2,3]) ") \\" _newline
file write `hh2' "  Number of success in 1985  & " %04.3f (result_85_1[1,4]) `star85_1_4'  "& " %04.3f (result_85_2[1,4]) `star85_2_4'  "& " %04.3f (result_85_3[1,4]) `star85_3_4' "& " %04.3f (result_85_4[1,4]) `star85_4_4' " \\" _newline
file write `hh2' "    & (" %04.3f (result_85_1[2,4]) ") & (" %04.3f (result_85_2[2,4]) ") & (" %04.3f (result_85_3[2,4]) ") & (" %04.3f (result_85_4[2,4]) ") \\" _newline
file write `hh2' "  Risk aversion in 2000  & " %04.3f (result_85_1[1,5]) `star85_1_5' "& " %04.3f (result_85_2[1,5]) `star85_2_5' "& " %04.3f (result_85_3[1,5]) `star85_3_5' "& " %04.3f (result_85_4[1,5]) `star85_4_5' " \\" _newline
file write `hh2' "    & (" %04.3f (result_85_1[2,5]) ") & (" %04.3f (result_85_2[2,5]) ") & (" %04.3f (result_85_3[2,5]) ") & (" %04.3f (result_85_4[2,5]) ") \\" _newline
file write `hh2' "  Hyperbolistic discounting in 2000  & " %04.3f (result_85_1[1,6]) `star85_1_6' "& " %04.3f (result_85_2[1,6]) `star85_2_6' "& " %04.3f (result_85_3[1,6]) `star85_3_6' "& " %04.3f (result_85_4[1,6]) `star85_4_6' " \\" _newline
file write `hh2' "    & (" %04.3f (result_85_1[2,6]) ") & (" %04.3f (result_85_2[2,6]) ") & (" %04.3f (result_85_3[2,6]) ") & (" %04.3f (result_85_4[2,6]) ") \\" _newline
file write `hh2' "  High discounting in 2000 & " %04.3f (result_85_1[1,7]) `star85_1_7' "& " %04.3f (result_85_2[1,7]) `star85_2_7' "& " %04.3f (result_85_3[1,7]) `star85_3_7' "& " %04.3f (result_85_4[1,7]) `star85_4_7' " \\" _newline
file write `hh2' "    & (" %04.3f (result_85_1[2,7]) ") & (" %04.3f (result_85_2[2,7]) ") & (" %04.3f (result_85_3[2,7]) ") & (" %04.3f (result_85_4[2,7]) ") \\" _newline
file write `hh2' "  Years of education  & " %04.3f (result_85_1[1,8]) `star85_1_8' "& " %04.3f (result_85_2[1,8]) `star85_2_8' "& " %04.3f (result_85_3[1,8]) `star85_3_8' "& " %04.3f (result_85_4[1,8]) `star85_4_8' " \\" _newline
file write `hh2' "    & (" %04.3f (result_85_1[2,8]) ") & (" %04.3f (result_85_2[2,8]) ") & (" %04.3f (result_85_3[2,8]) ") & (" %04.3f (result_85_4[2,8]) ") \\" _newline
file write `hh2' "  Years of education squared   & " %04.3f (result_85_1[1,9]) `star85_1_9' "& " %04.3f (result_85_2[1,9]) `star85_2_9' "& " %04.3f (result_85_3[1,9]) `star85_3_9' "& " %04.3f (result_85_4[1,9]) `star85_4_9' " \\" _newline
file write `hh2' "    & (" %04.3f (result_85_1[2,9]) ") & (" %04.3f (result_85_2[2,9]) ") & (" %04.3f (result_85_3[2,9]) ") & (" %04.3f (result_85_4[2,9]) ") \\" _newline
file write `hh2' "  Credit Constraint in 1985   & " %04.3f (result_85_1[1,10]) `star85_1_10' "& " %04.3f (result_85_2[1,10]) `star85_2_10' "& " %04.3f (result_85_3[1,10]) `star85_3_10' "& " %04.3f (result_85_4[1,10]) `star85_4_10' " \\" _newline
file write `hh2' "    & (" %04.3f (result_85_1[2,10]) ") & (" %04.3f (result_85_2[2,10]) ") & (" %04.3f (result_85_3[2,10]) ") & (" %04.3f (result_85_4[2,10]) ") \\" _newline

file write `hh2' "  Head's age & & X & X & \\" _newline
file write `hh2' "  Household size & & X & X & \\" _newline
file write `hh2' "  Head's age squared & & & X &  \\" _newline
file write `hh2' "  Household size squared & & & X & \\" _newline
file write `hh2' "  Head's age dummy (by 10 years each) & & & & X \\" _newline
file write `hh2' "  Household size dummy (by 3 people each) & & & & X \\" _newline

file write `hh2' "Adjusted R$^2$ & " %04.3f (Rsquared_85_1) " & " %04.3f (Rsquared_85_2) " & " %04.3f (Rsquared_85_3) " & " %04.3f (Rsquared_85_4) " \\" _newline

file write `hh2' " Observations & 399 &  399 & 399 & 399 \\ " _newline


file write `hh2' "\\\midrule" _newline
file write `hh2' "\end{tabular}" _newline
file write `hh2' "\begin{tablenotes}" _newline
file write `hh2' "\item \textsuperscript{a}: Controls: area of farmland, squared area of farmland, village dummy, risk aversion missing dummy, age missing dummy, and number of household missing dummy." _newline
file write `hh2' "\item \textsuperscript{b}: The asterisks ***, **, and * denote the 1 percent, 5 percent, and 10 percent levels of significance, respectively." _newline
file write `hh2' "" _newline
file write `hh2' "\end{tablenotes}" _newline
file write `hh2' "\end{threeparttable}" _newline
file write `hh2' "}" _newline
file write `hh2' "\label{tab:addlabel}%" _newline
file write `hh2' "\end{table}" _newline

file write `hh2' "" _newline
file write `hh2' "" _newline
file write `hh2' "" _newline
file write `hh2' "" _newline

file close `hh2'
